package com.yangwp.doutu.service.impl;

import com.google.common.collect.Maps;
import com.yangwp.doutu.dao.ImageGroupDao;
import com.yangwp.doutu.model.ImageGroup;
import com.yangwp.doutu.service.ImageGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.Map;

@Service
public class ImageGroupServiceImpl implements ImageGroupService {

    @Autowired
    private ImageGroupDao imageGroupDao;

    @Override
    public boolean insert(ImageGroup imageGroup){
        return imageGroupDao.insert(imageGroup) > 0;
    }

    @Override
    public ImageGroup get(ImageGroup imageGroup){
        Map<String, Object> cond = Maps.newHashMap();
        cond.put("name", imageGroup.getName());
        List<ImageGroup> groupList = imageGroupDao.getIamgeGroupList(cond);
        if(CollectionUtils.isEmpty(groupList)){
            return null;
        }
        return groupList.get(0);
    }

    @Override
    public boolean rollback(int num){
        return imageGroupDao.rollback(num) > 0;
    }
}
